package top.jsnow;

import top.jsnow.db.Condition;
import top.jsnow.db.Dao;
import top.jsnow.db.DaoMgr;
import top.jsnow.db.annotation.Table;

import java.sql.ResultSet;
import java.sql.SQLException;

public class TestDao {
    public static void main(String[] args) throws SQLException {
        Dao dao = DaoMgr.get();
        dao.create(User.class);
        dao.insert(new User("ZhangSan", 12));
        dao.insert(new User("Lisi", 22));
        ResultSet rs = dao.query(User.class,null);
        while(rs.next()){
            System.out.print(rs.getString("name"));
            System.out.println("\t"+rs.getInt("age"));
        }
        System.out.println("##############");
        rs = dao.query(User.class,new Condition("age","22"));
        while(rs.next()){
            System.out.print(rs.getString("name"));
            System.out.println("\t"+rs.getInt("age"));
        }
    }

}


@Table("t_user")
class User{
    private String name;
    private int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}